<?php

$func_name = "object_find.php";

$to_tpl = array();
$to_tpl['filename'] = 'object_find.tpl';
/**
 * @param	$data[]
 */
$to_tpl['data'] = array();




// Formular verarbeiten	
$find_obj = array();
if ('GET' == $_SERVER['REQUEST_METHOD']) {
    //Formulardaten erhalten
    log_message('[' . $func_name . ']' . GET_RECIVED);



    /**
     * TODO:
     * Eingaben überprüfen
     * * */
    // Objekt anlegen
    // Namen zuweisen
    if (array_key_exists('obj_name', $_GET)) {
        $find_obj['obj_name'] = $_GET['obj_name'];
        $to_tpl['data']['obj_name'] = $_GET['obj_name'];
    }

    // Kategorie zuweisen
    if (array_key_exists('cat_id', $_GET)) {
        if ((is_numeric($_GET["cat_id"])) && ($_GET["cat_id"] > 0)) {
            $find_obj['obj_cat_id'] = $_GET['cat_id'];
            $to_tpl['data']['cat_id'] = $_GET['cat_id'];
        }
    }

    // Kategorie inc. Kinder durchuchen?
    if (array_key_exists('cat_childn', $_GET)) {
        if ((is_numeric($_GET["cat_child"])) && ( ($_GET["cat_child"] == 1) || ($_GET["cat_child"] == 0) )) {
            $find_obj['cat_child'] = $_GET['cat_child'];
            $to_tpl['data']['cat_child'] = $find_obj['cat_child'];
        }
    }
}
$to_tpl['data']['objects'] = find_objects($find_obj);

//Image ID's in URLs übersetzen
foreach ($to_tpl['data']['objects'] as $tmp_id => $tmp_object) {
    if (isset($tmp_object["obj_img_id"])) {
        $to_tpl['data']['objects'][$tmp_id]["obj_img_url"] = get_image($tmp_object["obj_img_id"]);
    } else {
        $to_tpl['data']['objects'][$tmp_id]["obj_img_url"] = get_image(IMAGE_NA_ID);
    }
}
//var_dump($find_obj);
unset($tmp_id, $tmp_object, $func_name);
return $to_tpl;
?>

